using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VICC_IMAGES
    {
        public void SetUpNewRow(ref DataRow dwReturn, DataRow dwInput = null)
        {
            switch (app.company)
            {
                default:
                case "YGR":
                    #region====JLT======
                    dwReturn["MANDANT"] = app.Mandant;
                    dwReturn["ROWNID"] = "0";
                    dwReturn["KEY"] = " ";
                    dwReturn["IMAGE"] = Encoding.Default.GetBytes(" ".PadRight(20));
                    #endregion
                    break;
            }
            INTEXDBC.MapData(true, ref dwReturn, dwInput);
        }
        public void InsertICC_IMAGES(DataRow dwData, byte[] img, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                default:
                case "YGR":
                    or1.CommandText = "INSERT INTO ICC_IMAGES(MANDANT, ROWNID, KEY, IMAGE)"
                        + " VALUES (:MANDANT, :ROWNID, :KEY, :IMAGE)";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
                    or1.Parameters.Add("KEY", OracleType.NVarChar).Value = dwData["KEY"].ToString();
                    OracleParameter pama = new OracleParameter();
                    pama.ParameterName = "IMAGE";
                    pama.OracleType = OracleType.Blob;
                    pama.Direction = ParameterDirection.Input;
                    pama.Value = img;
                    or1.Parameters.Add(pama);
                    break;
            } 
            Connect2Proxy(or1);
        }
        public DataSet QueryICC_IMAGES(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ICC_IMAGES WHERE  ROWNUM<2 ";
                    break;
                case 1:
                    or1.CommandText = "SELECT * FROM ICC_IMAGES  WHERE MANDANT=:MANDANT: AND KEY=:KEY:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ICC_IMAGES";
            Return = Result;
            return Return;
        }
        public void DeleteICC_IMAGES(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ICC_IMAGES   WHERE  MANDANT=:MANDANT: AND KEY=:KEY:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }

        public void UpdateICC_IMAGES(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command====
                    or1.CommandText = "UPDATE ICC_IMAGES SET "
                    + "MANDANT= :MANDANT,"
                    + "ROWNID= :ROWNID,"
                    + "KEY= :KEY,"
                    + "IMAGE= :IMAGE,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
                    or1.Parameters.Add("KEY", OracleType.NVarChar).Value = dwData["KEY"].ToString();
                    or1.Parameters.Add("IMAGE", OracleType.NVarChar).Value = dwData["IMAGE"].ToString();
                    #endregion
                    break;
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
